﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Purchase.Infrastructure.Migrations
{
    public partial class info采购 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BillOfMaterial",
                columns: table => new
                {
                    BomId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    BomNumber = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    BomSubject = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    ProductName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    ProductCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Specification = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    Unit = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Quantity = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    ProductRole = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    ProcessFlow = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    LossRate = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
                    CreatedBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Remarks = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BillOfMaterial", x => x.BomId);
                });

            migrationBuilder.CreateTable(
                name: "BomComponent",
                columns: table => new
                {
                    ComponentId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    BomId = table.Column<int>(type: "int", nullable: false),
                    SequenceNumber = table.Column<int>(type: "int", nullable: false),
                    ProductName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    ProductCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Specification = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    Unit = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    ProductRatio = table.Column<decimal>(type: "decimal(18,4)", nullable: true),
                    Quantity = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    ProductRole = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    ProcessFlow = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    LossRate = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
                    PickingMethod = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Remarks = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BomComponent", x => x.ComponentId);
                    table.ForeignKey(
                        name: "FK_BomComponent_BillOfMaterial_BomId",
                        column: x => x.BomId,
                        principalTable: "BillOfMaterial",
                        principalColumn: "BomId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BomComponent_BomId",
                table: "BomComponent",
                column: "BomId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BomComponent");

            migrationBuilder.DropTable(
                name: "BillOfMaterial");
        }
    }
}
